package com.seekting.mynews.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.seekting.mynews.App;
import com.seekting.mynews.manager.BitmapRatioManager;
import com.seekting.mynews.manager.VolleyRequestManager;

/**
 * Created by seekting on 2016/3/21.
 */
public class RatioImageView extends NetworkImageView {

    private final BitmapRatioManager mBitmapRatioManager;

    private String mUrl;

    public RatioImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mBitmapRatioManager = App.getApp().getManager(VolleyRequestManager.class).getBitmapRatioManager();

    }

    @Override
    public void setImageUrl(String url, ImageLoader imageLoader) {
        super.setImageUrl(url, imageLoader);
        this.mUrl = url;
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        super.setImageBitmap(bm);
        if (bm != null) {
            float ratio = bm.getWidth() / bm.getHeight();
            mBitmapRatioManager.putRatio(mUrl, ratio);
        }

    }
}
